Creating Offline Web Applications in Macromedia Central
Table of Contents
How Central Uses Connection Awareness
Macromedia Central can recognize a user's connection status in two ways. In one method, when a user switches his/her connection state, it calls an event handler; in your application, you can call a method at any time to retrieve the current connection status. Well-designed applications use this connection awareness to create a seamless online and offline experience for users.
Note: Remember that users communicate their connection status to Central; Central cannot determine connection status directly. By selecting the lightning bolt in the Central toolbar, users can toggle between online and offline mode.
To set up your applications for connection awareness, use the following event handlers and functions in your ActionScript logic.
The onNetworkChange Shell, Agent, and Console Event Handler
The shell, agent, and console event handler onNetworkChange
alerts your application that the user has made changes to his connection
to the Internet or network. Keep in mind that Macromedia Central does
not detect if there is an Internet connection present; rather, it relies
on user interaction to transmit its state. Central calls the onNetworkChange
handler and passes a Boolean value as an argument indicating the new
connection status.
Example:
function onNetworkChange(connected)
{
gOnline = connected;
if (gOnline)
{
updateData();
}
}
The isConnected Function
Use the isConnected function to determine Central's connection
status during any step within your ActionScript logic. As a method of
the AgentManager, Shell, or Console, isConnected returns
a boolean value of true if the user is connected and false if the user
is offline. Because the onNetworkChange event handler is
only called when the user's online status changes, it is important to
call the event handler when initializing your application to transmit
the current connection state. This prevents you from having to write
isConnected calls throughout your application; likewise,
you can consolidate your connection management in the onNetworkChange
event.
Example:
function onActivate(shell)
{
/* set a variable to reference the AgentManager, Shell, or Console */
gShell = shell;
/* take current state and trigger onNetworkChange */
onNetworkChange( gShell.isConnected() );